package com.web.java0328springboot.controller;

import com.web.java0328springboot.entity.ResponseResult;
import com.web.java0328springboot.entity.User;
import com.web.java0328springboot.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 */
@CrossOrigin
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseResult login(String username,String password){
        User user = userService.login(username, password);
        return new ResponseResult(200,"OK",user);
    }

    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public ResponseResult update(User user){
        userService.updateById(user);
        return new ResponseResult(200,"OK",null);
    }
}
